package lcs;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

import lcs.hirschberg.Hirschberg;
import lcs.table.LCSTableFinder;

public class RunLCS {

	/**
	 * Receives strings as arguments, launches LCSFinder, handles results.
	 * 
	 * @param args the strings to find the LCS of
	 * @author Chris Carpenter
	 * @author Lance Hymel
	 * @author Charles Cobb
	 * @throws IOException 
	 */
	public static void main(String[] args) {
		//REUSABLE VARs
		long time, memory;
		String lcs;
		try{
		//GET INPUT
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        System.out.println("Enter the first string: ");
        String string1 = br.readLine();
        System.out.println("Enter the second string: ");
        String string2 = br.readLine();
        
        
		//DYNAMIC
		LCSTableFinder finder = new LCSTableFinder();
		System.gc();
		time = System.currentTimeMillis();
		lcs = finder.findSingleLCS(string1, string2);
		memory = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024;
		time = System.currentTimeMillis()-time;
		System.out.println("\nDYNAMIC PROGRAMMING:\n" +
				"Theoretical memory required: O("+ 
        		(string1.length()+1)*(string2.length()+1) +
        		")\tTheoretical time required: O("+
        		(string1.length())*(string2.length())
        		+")\nActual time required: " +
        		time+"ms\tActual memory required: " +
        		memory+"KB\n");
		
		
		
		
		
		//HIRSCHBERG
		Hirschberg algorithm = new Hirschberg();
		System.gc();
		time = System.currentTimeMillis();
		lcs = algorithm.getLCS(string1.length(), string2.length(), string1, string2);
		memory = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024;
		time = System.currentTimeMillis()-time;
		System.out.println("HIRSCHBERG:\n" +
				"Theoretical memory required: O("+ 
				((string1.length() > string2.length()) ? string1 : string2).length()*2 +
        		")\tTheoretical time required: O("+
        		(string1.length())*(string2.length())
        		+")\nActual time required: " +
        		time+"ms\tActual memory required: " +
        		memory+"KB\n");
		
		
		System.out.println("\nLCS: " + lcs);
		}
		catch (IOException e){}
	}
}
